<template>
  <div>
    <el-container>
      <el-main>
        <kendoForm
          :kendo-form-items="kendoFormItems"
          :kendo-form="kendoForm"
          :kendo-params-value="kendoParamsValue"
        />
      </el-main>
    </el-container>
    <el-container style="padding-left:5px">
      <el-main>
        <KendoGridCmpt
          :ref="'StandingBookKendoGrid'"
          :table-grid-option="tableGridOption"
          :table-grid-data-source-option="tableGridDataSourceOption"
          :table-grid-toolbar="tableGridToolbar"
          @persistSelection="selectDataItems"
        />
      </el-main>
    </el-container>
  </div>
</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  // import { isBlank } from '@/Utils/strUtil.js'
  export default {
    name: 'StandingBookPage',
    components: {
      kendoForm
    },
    data() {
      return {
        /* Form*/
        kendoFormItems: [
          {
            name: 'reqNo',
            label: '需求名称',
            paramName: 'reqNo',
            controlType: 'multicolumncombobox',
            // change: this.devInChargeChange,
            dataSource: 'PrjReqTaskDataSource',
            dataType: 'json',
            transportReadUrl: '/service/prjMng/reqmntTaskMng/findReqMntTaskList',
            dataMapping: {
              label: 'reqName',
              value: 'reqNo'
            },
            schema: {
              data: function(response) {
                if (typeof response.data === 'object') {
                  if (JSON.stringify(response.data) === '{}') {
                    return []
                  }
                }
                return response.data
              }
            },
            column: [
              {
                field: 'reqNo',
                title: '需求编号',
                width: 180
              },
              {
                field: 'reqName',
                title: '需求名称',
                width: 320
              }
            ]
          }
        ],
        kendoForm: {
          ref: 'StandingBookSearchForm',
          valid: 'valid',
          buttons: [
            {
              name: '查询', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'search',
              click: this.search
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm',
              click: this.reset
            }
          ],
          rules: {},
          message: {}
        },
        kendoParamsValue: {
          reqNo: ''
        },
        /* Form*/
        /* Grid*/
        // maintain 需求信息数据列表
        tableGridOption: {
          ref: 'FpDetailKendoGrid',
          dataSourceRef: 'reqFpDetailDataSource',
          remoteData: true,
          sortable: true,
          reorderable: true,
          resizable: true,
          pageable: true,
          selectSingle: true,
          selectMultiple: false,
          toolbar: ['excel'],
          excel: {
            fileName: '需求任务明细表',
            allPages: true
          },
          columns: [
            {
              field: 'reqNo',
              title: '需求名称',
              width: 240,
              dictData: 'REQ_NO_CD'
            },
            {
              field: 'fpName',
              title: '功能点明细',
              width: 360
            },
            {
              field: 'fpType',
              title: '功能点类别',
              width: 120,
              dictData: 'FP_TYPE_CD'
            },
            {
              field: 'fcDivision',
              title: '功能性划分',
              width: 120,
              dictData: 'FC_DIVISION_CD'
            },

            {
              field: 'cmplRate',
              title: '完成比例',
              width: 100,
              format: '{0:p2}'
            },
            {
              field: 'whetherCmpl',
              title: '是否完成',
              width: 80,
              dictData: 'WHETHER_CMPL_CD'
            },
            {
              field: 'cmplDt',
              title: '完成日期',
              width: 120
            }
          ]
        },
        tableGridDataSourceOption: {
          ref: 'StandingBookDataSource',
          type: 'json',
          pageSize: 10,
          transportReadUrl: '/service/prjMng/reqmntFpDetail/findReqMntFpPage',
          serverPaging: true,
          dict: ['FC_DIVISION_CD', 'WHETHER_CMPL_CD', 'FP_TYPE_CD'],
          remoteTransData: {
            REQ_NO_CD: {
              transportName: 'reqmntTaskServiceImpl',
              transportMethod: 'reqTaskNoTransDict',
              transportParam: {}
            }
          },
          params: {},
          schema: {
            model: {
              id: 'id',
              fields: {
                reqNo: { editable: false, type: 'string' },
                fpName: { editable: false, type: 'string' },
                fpType: { editable: false, type: 'string' },
                fcDivision: { editable: false, type: 'string' },
                cmplRate: { editable: false, type: 'number' },
                whetherCmpl: { editable: false, type: 'string' },
                cmplDt: { editable: false, type: 'string' }
              }
            },
            data: function(response) {
              return response.data.list
            },
            total: function(response) {
              return response.data.total
            }
          }
        },
        selectData: []
      }
    },
    mounted() {

    },
    methods: {
      /* grid*/
      parameterMap(options, operation) {
        if (operation !== 'read' && options.models) {
          // eslint-disable-next-line no-undef
          return { models: kendo.stringify(options.models) }
        } else {
          let parameterMap = this.tableGridDataSourceOption.params
          parameterMap.pageNum = options.page
          parameterMap.pageSize = options.pageSize
          parameterMap = Object.assign(parameterMap, this.deepCopy(this.kendoParamsValue))
          return {
            // eslint-disable-next-line no-undef
            parameterMap: kendo.stringify(parameterMap)
          }
        }
      },
      selectDataItems(res) {
        this.selectData = res
      },
      search(paramVal, validator) {
        this.tableGridDataSourceOption.params = Object.assign(this.tableGridDataSourceOption.params, this.deepCopy(paramVal))
        this.$refs['StandingBookKendoGrid'].transportReadGrid()
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (Array.isArray(paramVal[key])) {
            this.kendoParamsValue[key] = []
          } else {
            this.kendoParamsValue[key] = ''
          }
        })
        this.$refs['StandingBookKendoGrid'].transportReadGrid()
      }
    }
  }
</script>

<style>

</style>
